<!DOCTYPE html>
<html>
<head>
    <title>Physics Inclined Plane</title>
</head>
<body>
<canvas id="physicsCanvas" width="550" height="520" style="border:1px solid #000000;"></canvas>
<script>
    const canvas = document.getElementById('physicsCanvas');
    const ctx = canvas.getContext('2d');

    // Define geometry parameters based on the image
    const startX = 50;
    const startY = 450;
    const base = 400; // Represents 4.0 m
    const height = 300; // Represents 3.0 m

    // Draw the inclined plane (triangle)
    ctx.beginPath();
    ctx.moveTo(startX, startY);
    ctx.lineTo(startX + base, startY);
    ctx.lineTo(startX + base, startY - height);
    ctx.closePath();
    ctx.lineWidth = 2;
    ctx.strokeStyle = 'black';
    ctx.stroke();

    // Draw the right angle symbol
    ctx.beginPath();
    ctx.moveTo(startX + base - 20, startY);
    ctx.lineTo(startX + base - 20, startY - 20);
    ctx.lineTo(startX + base, startY - 20);
    ctx.lineWidth = 1.5;
    ctx.stroke();

    // --- Draw Dimensions ---
    ctx.lineWidth = 1;
    ctx.font = 'bold 22px Arial';
    ctx.fillStyle = 'black';
    ctx.textAlign = 'center';
    ctx.textBaseline = 'middle';

    // Base dimension (4.0 m)
    const dimYBase = startY + 30;
    ctx.beginPath();
    ctx.moveTo(startX, dimYBase);
    ctx.lineTo(startX + base, dimYBase);
    // Left arrowhead
    ctx.moveTo(startX + 10, dimYBase - 5);
    ctx.lineTo(startX, dimYBase);
    ctx.lineTo(startX + 10, dimYBase + 5);
    // Right arrowhead
    ctx.moveTo(startX + base - 10, dimYBase - 5);
    ctx.lineTo(startX + base, dimYBase);
    ctx.lineTo(startX + base - 10, dimYBase + 5);
    ctx.stroke();
    ctx.fillText("4.0 m", startX + base / 2, dimYBase + 20);

    // Height dimension (3.0 m)
    const dimXHeight = startX + base + 30;
    ctx.beginPath();
    ctx.moveTo(dimXHeight, startY);
    ctx.lineTo(dimXHeight, startY - height);
    // Top arrowhead
    ctx.moveTo(dimXHeight - 5, startY - height + 10);
    ctx.lineTo(dimXHeight, startY - height);
    ctx.lineTo(dimXHeight + 5, startY - height + 10);
    // Bottom arrowhead
    ctx.moveTo(dimXHeight - 5, startY - 10);
    ctx.lineTo(dimXHeight, startY);
    ctx.lineTo(dimXHeight + 5, startY - 10);
    ctx.stroke();
    ctx.fillText("3.0 m", dimXHeight + 30, startY - height / 2);

    // --- Draw Block M ---
    const angle = Math.atan2(height, base);
    const blockDistAlongIncline = 100; // Distance from the bottom corner
    const blockCenterX = startX + blockDistAlongIncline * Math.cos(angle);
    const blockCenterY = startY - blockDistAlongIncline * Math.sin(angle);
    const blockSize = 50;

    ctx.save();
    ctx.translate(blockCenterX, blockCenterY);
    ctx.rotate(-angle);

    // Draw red box
    ctx.fillStyle = 'red';
    ctx.fillRect(-blockSize / 2, -blockSize / 2, blockSize, blockSize);
    ctx.strokeStyle = 'black';
    ctx.lineWidth = 2;
    ctx.strokeRect(-blockSize / 2, -blockSize / 2, blockSize, blockSize);

    // Draw letter M
    ctx.fillStyle = 'black';
    ctx.font = 'bold 24px Arial';
    ctx.textAlign = 'center';
    ctx.textBaseline = 'middle';
    ctx.fillText('M', 0, 0);

    ctx.restore();

    // --- Draw Force Vector F ---
    const forceLength = 100;
    const forceEndX = blockCenterX + forceLength * Math.cos(angle);
    const forceEndY = blockCenterY - forceLength * Math.sin(angle);

    ctx.beginPath();
    ctx.moveTo(blockCenterX, blockCenterY);
    ctx.lineTo(forceEndX, forceEndY);
    ctx.strokeStyle = 'blue';
    ctx.lineWidth = 3;
    ctx.stroke();

    // Draw arrowhead for force F
    ctx.save();
    ctx.translate(forceEndX, forceEndY);
    ctx.rotate(-angle);
    ctx.beginPath();
    ctx.moveTo(0, 0);
    ctx.lineTo(-12, -6);
    ctx.moveTo(0, 0);
    ctx.lineTo(-12, 6);
    ctx.strokeStyle = 'blue';
    ctx.lineWidth = 3;
    ctx.stroke();
    ctx.restore();

    // --- Draw Force Label ---
    ctx.fillStyle = 'black';
    ctx.font = 'bold 24px Arial';
    ctx.textAlign = 'left';
    ctx.textBaseline = 'bottom';
    ctx.fillText("F=150 N", blockCenterX - 70, blockCenterY - 60);

</script>
</body>
</html>